package cn.xs.core.util;

import java.util.Date;

public class TimeUtils {

	Date time = new Date();
	String monthTime = null;
	String monthLastTime = null;
	
	public String getTime(){
		String t = time.toLocaleString();
		int idx = t.indexOf(" ");
		return t.substring(0,idx);
	}
	
	private String getTime0(){
		String t = time.toLocaleString();
		return t.substring(0,6);
	}
	/**
	 * return 20xx-xx-01
	 * @return
	 */
	public String getMonthTime(){
		if(monthTime==null){
			String time = getTime0();
			monthTime=time+"-01";
		}
		return monthTime;
	}
	
	public String getLastMonthTime(){
		if(monthLastTime==null){
			String time = getTime0();
			int month = Integer.parseInt(time.substring((time.length()-1)));
			month++;
			monthLastTime = time.substring(0, time.length()-1)+month+"-01";
		}
		return monthLastTime;
	}
}
